package com.olclass.web.util;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement(name = "BaseResponse")
@XmlAccessorType(XmlAccessType.NONE)
public class BaseResponse {

	@XmlElement
	protected String status = CommonConstants.RESPONSE_STATUS_OK;

	@XmlElement
	protected String message = "";

	public String getStatus() {
		return status;
	}

	public void setStatus(String status) {
		this.status = status;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public static BaseResponse buildNoLoginResponse() {
		BaseResponse response = new BaseResponse();

		response.setStatus(CommonConstants.RESPONSE_STATUS_LOGINOUT);
		response.setMessage("用户未登录或已登录超时，请重新登录!");

		return response;
	}

	public static BaseResponse buildFailuaResponse(Exception e) {
		BaseResponse response = new BaseResponse();
		response.setStatus(CommonConstants.RESPONSE_STATUS_FAILURE);
		response.setMessage(e.getMessage());
		return response;
	}

	public static BaseResponse buildFailuaResponse(String error) {
		BaseResponse response = new BaseResponse();
		response.setStatus(CommonConstants.RESPONSE_STATUS_FAILURE);
		response.setMessage(error);
		return response;
	}
	
	public static BaseResponse buildSuccessResponse(){
		BaseResponse response = new BaseResponse();
		response.setStatus(CommonConstants.RESPONSE_STATUS_OK);
		return response;	
	}
	
	public static BaseResponse buildSuccessResponse(String message){
		BaseResponse response = new BaseResponse();
		response.setStatus(CommonConstants.RESPONSE_STATUS_OK);
		response.setMessage(message);
		return response;	
	}

}
